<template>
	<view>
		<back :showBackText="false" customClass="bg-gradual-blue text-white" title="赠送会员"></back>
		<view v-if="isLoad">
			<view class="cu-bar bg-white solid-top">
				<view class="action">
					<text class="cuIcon-titles text-blue"></text> 第一步：填写会员编号
				</view>
			</view>
			<view class="cu-form-group solid-top">
				<input @input="uidInputTap" maxlength="32" placeholder="请填写对方会员编号" placeholderStyle="color:#999;"
					type="text" value="" />
			</view>
			<view class="cu-bar bg-white solid-top">
				<view class="action">
					<text class="cuIcon-titles text-blue"></text> 第二步：选择要赠送的会员
				</view>
			</view>
			<view class="flex flex-direction">
				<radio-group class="block" @change="vipListChangeTap">
					<view class="cu-list menu text-left">
						<view class="cu-item solid-top text-red" v-for="(item, index) in info.vip_list" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="flex-sub">{{ item.name }}【{{ item.expire_name }}到期】</view>
								<radio class="round" :class="radio=='radio' + index?'checked':''"
									:checked="radio=='radio' + index?true:false" :value="item.vid"></radio>
							</label>
						</view>
					</view>
				</radio-group>
			</view>
			<view class="padding flex flex-direction margin-top-xs">
				<button @tap="submitTap" class="cu-btn bg-blue lg">确认赠送</button>
			</view>
			<view class="cu-bar bg-white" style="border-bottom: 1px solid #f2f2f2">
				<view class="action">
					<text class="cuIcon-titles text-blue"></text>
					<text class="" style="color:#666666">操作说明</text>
				</view>
			</view>
			<view class="cu-list menu">
				<view class="cu-item" v-for="(notice, index) in info.notice_list" :key="index">
					<view class="content">
						<text class="text-grey">{{ notice }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	let app = getApp();
	let that = null;
	export default {
		data() {
			return {
				info: {},
				isLoad: false,
				selectVipId: 0,
				selectUserId: 0,
				showUserInfo: false
			};
		},
		onLoad(t) {
			that = this;
			app.globalData.checkAppIsAuditAndRedirect();
		},
		onShow() {
			that.getInfo();
		},
		methods: {
			async getInfo() {
				let res = await app.globalData.service.vipTransferInfo();
				that.info = res.data
				that.isLoad = true;
			},
			uidInputTap(options) {
				that.selectUserId = options.detail.value;
			},
			vipListChangeTap(options) {
				that.selectVipId = options.detail.value;
			},
			submitTap() {
				if (!that.selectUserId) {
					app.showToast('请先填写用户编号');
					return;
				}
				if (!that.selectVipId) {
					app.showToast('请先选择要赠送的会员');
					return;
				}
				uni.showModal({
					content: '确认赠送？',
					success: function(res) {
						if (res.confirm) {
							uni.login({
								async success(res) {
									console.log(res)
									let code = res.code
									if (code) {
										let data = {
											uid: that.selectUserId,
											vid: that.selectVipId,
											code: code
										}
										let res = await app.globalData.service.vipTransfer(data);
										app.showToast('操作成功');
										setTimeout(() => {
											that.getInfo();
										}, 1500);
									} else {
										app.showToast('获取用户身份失败');
									}
								}
							})
						}
					}
				});
			}
		}
	};
</script>
<style>
	@import './transfer.css';
</style>
